package com.zhz.leetcode;

/**
 * 485、最大连续1的个数
 * https://leetcode-cn.com/problems/max-consecutive-ones/
 */
public class FindMaxConsecutiveOnes485 {

    public static void main(String[] args) {
        //nums = [1,1,0,1,1,1] return 3
        //nums = [1,0,1,1,0,1] return 2
        FindMaxConsecutiveOnes485 a = new FindMaxConsecutiveOnes485();
        int[] nums = {1, 0, 1, 1, 1, 1, 1, 1};
        int max = a.findMaxConsecutiveOnes(nums);
        System.out.println("max : " + max);
    }

    public int findMaxConsecutiveOnes(int[] nums) {
        int tmp = 0;
        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 1) {
                tmp ++;
            } else {
                max =  Math.max(max,tmp);
                tmp = 0;
            }
        }
        return Math.max(max,tmp);
    }


}
